// Describe:
package init

import (
	"gitee.com/bishisimo/log-parser/console"
	"gitee.com/bishisimo/log-parser/parser"
	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
	"github.com/rs/zerolog/pkgerrors"
	"github.com/spf13/viper"
)

func initLog() {
	zerolog.CallerSkipFrameCount = 2 //这里根据实际，另外获取的是Msg调用处的文件路径和行号
	zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
	out := console.NewConsoleWriter(parser.NewZeroLogParser("wormhole"))
	log.Logger = log.Output(out).With().Caller().Stack().Logger()
	level, err := zerolog.ParseLevel(viper.GetString("log.level"))
	if err != nil {
		level = zerolog.InfoLevel
	}
	zerolog.SetGlobalLevel(level)
	log.Debug().Str("log-lever", viper.GetString("log.level")).Send()
}
